const axios = require('axios');
const cozeToken = require('./cozeToken');

// 上传文件
async function uploadFile(file) {
	try {
		const headers = await cozeToken.getAuthHeaders();
		const formData = new FormData();
		formData.append('file', file);

		const response = await axios.post(
			'https://api.coze.cn/v1/file/upload',
			formData,
			{
				headers: {
					...headers,
					'Content-Type': 'multipart/form-data'
				}
			}
		);
		return response.data;
	} catch (error) {
		console.error('上传文件失败:', error);
		throw error;
	}
}

module.exports = {
	uploadFile
};